<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>长度为三的不同回文子序列</title>
</head>
<body>
  <script>
    function fn(s) {
      const n = s.length;
      if (n < 3) return 0
      const s1 = new Set()
      const s2 = new Set()
      let count = 0;
      for (let i = 0; i < n; i++) {
        if (i > 0 && s[i] === s[i - 1]) continue
        if (!s1.has(s[i])) {
          s1.add(s[i])
          let L = i + 1;
          let R = s.lastIndexOf(s[i])
          if (R <= L) continue
          while (L < R) {
            if (!s2.has(s[L])) {
              count++
              s2.add(s[L])
            }
            L++
          }
          s2.clear()
        }
      }
      return count
    }
    console.log(fn('aabca'))
  </script>
</body>
</html>